package cn.gson.springboot.model.service;

import cn.gson.springboot.model.dao.ChatRecordDao;
import cn.gson.springboot.model.mapper.ChatRecordMapper;
import cn.gson.springboot.model.pojos.ChatRecord;
import cn.gson.springboot.model.vo.ChatRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

@Service
public class ChatRecordService {
    @Autowired
    ChatRecordMapper chatMapper;
    @Autowired
    ChatRecordDao chatDao;
    public List<ChatRecord> selectChatRecordByTaskId(Integer taskId){
        return chatMapper.selectChatRecordByTaskId(taskId);
    }

    @Transactional(transactionManager = "transactionManager")
    public void saveChatRecord(ChatRecordVo vo){
        // 先增主表
        ChatRecord chat = new ChatRecord();
        chat.setChatRecordId(vo.getChatRecordId());
        chat.setChatRecordContent(vo.getChatRecordContent());
        chat.setChatRecordDate(new Timestamp(System.currentTimeMillis()));
        chat.setTaskByTaskId(vo.getTaskByTaskId());
        chat.setEmployeeByEmpId(vo.getEmployeeByEmpId());
        chatDao.save(chat);
    }

}
